<?php

namespace eu\freeplace\core;

use eu\freeplace\core\Constants as Constants;

/**
 * Load the Configuration of the application from a xml File.
 * This Class is whitout Logging, because the Logger needs the Configurtion
 * for working. This Problem is like the Chicken and the Egg.
 *
 * @author Elmar Dott
 * @version 1.0
 */
class ConfigurationLoader {

    const CLASS_NAME = "ConfigurationLoader";

    //Singelton Pattern =============================================
    static private $instance = null;
    static public function getInstance() {
        if (null === self::$instance) {
            self::$instance = new self;
        }
        return self::$instance;
    }
    /** Private Constructor implements a Singelton. */
    private function ConfigurationLoader() {/* NOT IN USE */}
    #================================================================

    /**
     * Load the configuration File.
     * 
     * @global Logger $logger
     * @return Array Configuration
     * @throws Exception 
     */
    public function loadConfiguration() {

        try {
           # $config = $this->mergeConfiguration();
            $config = $this->loadFileFromWebInfFolder();
            
            $entrieCount = sizeof($config);
            if ($entrieCount < 1) {
                throw new Exception("ConfigurationLoader.load() :: Could not read the Configuration");
            }
            
        } catch (Exception $e) {
            $e->getMessage();
        }
        return $config;
    }

    private function mergeConfiguration() {
        
        $packageScope     = $this->loadFileFromPackage();
        $applicationScope = $this->loadFileFromWebInfFolder();
        return array_merge($packageScope, $applicationScope);
    }
    
    private function loadFileFromWebInfFolder() {
        return simplexml_load_file(Constants::CONFIGURATION_DEFAULT_FILE);
    }
        
    private function loadFileFromPackage() {
        return null;
    }
}//CLASS

?>